Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    user: {
      phone: '',
      password: '',
      confirmPassword: '',
      code: ''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getVerificationCode() {
      wx.request({
        url: 'https://ufhmfcbjuwjt.sealoshzh.site/user/validCode/phone',
        method: 'GET',
        header: {
          'Content-Type': 'application/json' 
        },
        data: {
          "phone": this.data.user.phone,
        },
        success(res) {
          console.log('验证码成功');
        },
        fail(err) {
          console.error(err);
        }
      })
    },
    register(){
      if(this.data.user.phone === ''){
        console.log('手机号不能为空！')
      }
      else if(this.data.user.password === ''){
        console.log('密码不能为空!')
      }
      else if(this.data.user.confirmPassword!==this.data.user.password){
        console.log('密码不一致!请重新输入!')
      }
      else if(this.data.user.code === ''){
        console.log('验证码不能为空!')
      }
      else{
        wx.request({
          url: 'https://ufhmfcbjuwjt.sealoshzh.site/user/register',
          method:'POST',
          header: {
            'Content-Type': 'application/json' 
          },
          data: this.data.user,
          success(res){
            console.log('注册成功'),
            wx.navigateTo({
              url: '/pages/main/main',
            })
          },
          fail(err){
            console.log(err)
          }
        })
      }
    },
    onPhoneChange(e) {
      const phone = e.detail.value;
      this.setData({
        'user.phone': phone
      });
    },
    onPasswordChange(e) {
      const password = e.detail.value;
      this.setData({
        'user.password': password
      });
    },
    onConfirmPasswordChange(e) {
      const confirmPassword = e.detail.value;
      this.setData({
        'user.confirmPassword': confirmPassword
      });
    },
    onCodeChange(e) {
      const code = e.detail.value;
      this.setData({
        'user.code': code
      });
    },
  }
})